package src.main.StructuralPatterns.Proxy.JDK;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class TimingHandler implements InvocationHandler {
    private Object target;
    public TimingHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
       long start = System.currentTimeMillis();
       Object result = method.invoke(target, args);
       Thread.sleep(5000);
       long end = System.currentTimeMillis();

        System.out.printf("spend time: %d\n", end - start);
        return result;
    }
}
